﻿package mortal.game.view.guild.otherpanel
{
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildWareHouseApplyMoney extends GuildOtherBasePanel
    {
        private var _inputGlod:GTextInput;
        private var _inputCoin:GTextInput;
        private var _btnGoldOk:GButton;
        private var _btnCoinOk:GButton;
        private var _txtGold:GTextFiled;
        private var _txtCoin:GTextFiled;
        private static var _instance:GuildWareHouseApplyMoney;

        public function GuildWareHouseApplyMoney(param1:ILayer = null)
        {
            setSize(260, 240);
            super(param1);
            if (_instance)
            {
                throw new Error("单例");
            }
            title = "" + Language.getString(71235);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            paddingBottom = 10;
            return;
        }// end function

        override public function layoutUI() : void
        {
            super.layoutUI();
            UIFactory.bitmap(ImagesConst.Yuanbao, 29, 46, this);
            UIFactory.bitmap(ImagesConst.Jinbi, 30, 72, this);
            this._inputGlod = UIFactory.gTextInput(51, 47, 100, 22, this);
            this._inputCoin = UIFactory.gTextInput(51, 70, 100, 22, this);
            this._btnGoldOk = UIFactory.gButton("" + Language.getString(71236), 167, 47, 65, 22, this);
            this._btnCoinOk = UIFactory.gButton("" + Language.getString(71236), 167, 70, 65, 22, this);
            UIFactory.bg(4, 107, 252, 1, this, ImagesConst.SplitLine);
            UIFactory.bg(4, 167, 252, 1, this, ImagesConst.SplitLine);
            var _loc_1:* = Language.getStringByParam(71237, HTMLUtil.addColor(GuildConst.ApplyGoldMinValue.toString(), GlobalStyle.colorHuang)) + "<br/>     " + Language.getStringByParam(71238, HTMLUtil.addColor(GuildConst.ApplyCoinMinValue.toString(), GlobalStyle.colorHuang));
            _loc_1 = HTMLUtil.addColor(_loc_1, GlobalStyle.colorLv);
            var _loc_2:* = UIFactory.textField("", 19, 119, 255, 44, this);
            _loc_2.multiline = true;
            _loc_2.htmlText = _loc_1;
            var _loc_3:* = Language.getString(71239) + HTMLUtil.addColor(Language.getString(71240), GlobalStyle.colorHuang) + Language.getString(71241);
            var _loc_4:* = UIFactory.textField(_loc_3, 19, 179, 150, 22, this);
            _loc_4.htmlText = _loc_3;
            UIFactory.bitmap(ImagesConst.Yuanbao, 60, 202, this);
            UIFactory.bitmap(ImagesConst.Jinbi, 135, 203, this);
            this._txtGold = UIFactory.gTextField("55", 80, 203, 50, 20, this);
            this._txtCoin = UIFactory.gTextField("54235", 154, 203, 50, 20, this);
            return;
        }// end function

        override public function onMouseClick(event:MouseEvent) : void
        {
            var _loc_3:int = 0;
            super.onMouseClick(event);
            var _loc_2:* = new Dictionary();
            switch(event.target)
            {
                case this._btnCoinOk:
                {
                    _loc_3 = int(this._inputCoin.text);
                    if (_loc_3 < GuildConst.ApplyCoinMinValue || _loc_3 > Cache.instance.guild.selfGuildInfo.wareHouse.moneyDic[EPriceUnit._EPriceUnitCoin])
                    {
                        MsgManager.showRollTipsMsg("" + Language.getString(71242));
                        return;
                    }
                    _loc_2[EPriceUnit._EPriceUnitCoin] = this._inputCoin.text;
                    this.request(_loc_2);
                    break;
                }
                case this._btnGoldOk:
                {
                    _loc_3 = int(this._inputGlod.text);
                    if (_loc_3 < GuildConst.ApplyGoldMinValue || _loc_3 > Cache.instance.guild.selfGuildInfo.wareHouse.moneyDic[EPriceUnit._EPriceUnitGold])
                    {
                        MsgManager.showRollTipsMsg("" + Language.getString(71243));
                        return;
                    }
                    _loc_2[EPriceUnit._EPriceUnitGold] = this._inputGlod.text;
                    this.request(_loc_2);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function request(param1:Dictionary) : void
        {
            var _loc_2:Object = {};
            if (GuildConst.hasPermissions(GuildConst.ManagerWareHouse))
            {
                _loc_2.oper = new EGuildWarehouseOper(EGuildWarehouseOper._EGuildWarehouseOut);
                _loc_2.item = null;
                _loc_2.oprMoney = param1;
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guild_wareHouse_oper, _loc_2));
            }
            else
            {
                _loc_2.uid = "";
                _loc_2.amount = 0;
                _loc_2.donateMoney = param1;
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guild_wareHouse_applyRequst, _loc_2));
            }
            this.hide();
            return;
        }// end function

        override public function update() : void
        {
            super.update();
            this._inputCoin.text = GuildConst.ApplyCoinMinValue.toString();
            this._inputGlod.text = GuildConst.ApplyGoldMinValue.toString();
            this._txtCoin.text = Cache.instance.guild.selfGuildInfo.wareHouse.moneyDic[EPriceUnit._EPriceUnitCoin];
            this._txtGold.text = Cache.instance.guild.selfGuildInfo.wareHouse.moneyDic[EPriceUnit._EPriceUnitGold];
            return;
        }// end function

        override protected function configParams() : void
        {
            super.configParams();
            paddingBottom = 10;
            return;
        }// end function

        public static function get instance() : GuildWareHouseApplyMoney
        {
            if (_instance == null)
            {
                _instance = new GuildWareHouseApplyMoney;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
